package com.jbp.service;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jbp.dao.BannerDao;
import com.jbp.model.*;
import com.jbp.redis.RedisConfigService;
import com.jbp.utils.StrToMillsUtil;
import com.mysql.cj.util.StringUtils;
import com.mysql.cj.util.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * (Banner)表服务实现类
 * @author cc
 * @since 2020-06-30 22:48:04
 */
@Service
public class EventService extends ServiceImpl<BannerDao, Banner> {

    @Autowired
    private LotteryService lotteryService;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private WalletRecordService walletRecordService;
    @Autowired
    private UserService userService;
    @Autowired
    private RoomService roomService;

    public static final String key_cahe_contribution = "cache:lianmeng:contribution";
    public static final String key_cahe_hahaniu2 = "cache:event:key_cahe_hahaniu2";
    public static final String key_cahe_naonao1 = "cache:event:key_cahe_naonao1";
    public static final String key_cahe_naonao2 = "cache:event:key_cahe_naonao2";
    public static final String key_cahe_haiou = "cache:event:haiou";
    public static final String key_cahe_hd5 = "cache:event:hd5";
    /**
     * 贡献榜活动
     * 规则：出两个累计活动奖池（一个单日奖池，一个总活动期间奖池）。
     * 各抽抽奖投入的0.5%累计，抽奖前10名的玩家瓜分累计奖池。
     *
     * 1.单日奖池，每日拿出今日投入量的0.5%，累计进单日活动奖池中（实时显示活动奖池的数额），
     * 单日富豪榜的前10名瓜分单日鱼饼奖池（第一名30%，第二名20%，第三名15%，第四名-第十名每人分5%。
     *
     * 2.总奖池，拿出活动期间总投入量的0.5%，累计进总活动期间奖池中（实时显示活动奖池的数额），
     * 总富豪榜的前10名瓜分单日鱼饼奖池（第一名30%，第二名20%，第三名15%，第四名-第十名每人分5%）。
     *
     * */
    public Map<String, Object> contribution() {
        //取缓存  如果没有 再取数据库
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String json = (String) valueOperations.get(key_cahe_contribution);

        Map<String, Object> cache = (Map<String, Object>) JSON.parse(json);
        if (cache==null) {
            Map<String, Object> map = new HashMap<>();
            map.put("zrjc", 0);
            map.put("jrjc", 0);
            map.put("zjc", 0);
            map.put("zrbd",new ArrayList<>());
            map.put("jrbd",new ArrayList<>());
            map.put("zbd",new ArrayList<>());
            //活动未开始
            return map;
        }
        return cache;
    }

    //刷新贡献榜活动数据
    public Map<String, Object> refreshContribution() {
        System.out.println("刷新活动数据");
        String startDate = "2020-08-21"; //活动开始时间
        String endDate = "2020-08-27";  //活动结束时间
        String lastDate = "2020-08-28";  //活动结束时间
        String zrlastDate = "2020-08-29";  //活动结束时间
        //检查活动时间
        long start = StrToMillsUtil.strToMillsShort(startDate);
        long end = StrToMillsUtil.strToMillsShort(endDate);
        long last = StrToMillsUtil.strToMillsShort(lastDate);
        long zrlast = StrToMillsUtil.strToMillsShort(zrlastDate);
        long current = System.currentTimeMillis()/1000;

        if (start>current) {
            Map<String, Object> map = new HashMap<>();
            map.put("zrjc", 0);
            map.put("jrjc", 0);
            map.put("zjc", 0);
            map.put("zrbd",new ArrayList<>());
            map.put("jrbd",new ArrayList<>());
            map.put("zbd",new ArrayList<>());
            //活动未开始
            return map;
        }

        //不通用户分成点数
        double[] guize = new double[]{0.3d, 0.2d, 0.15d, 0.05d, 0.05d, 0.05d, 0.05d, 0.05d, 0.05d, 0.05d};

        //昨日奖池
        long zrjc = 0;
        List<EventUserLuckBangdanModel> zrbd = new ArrayList<>();
        //昨日榜单
        if (!startDate.equals(StrToMillsUtil.millsToStrDate(new Date(), null)) && current<zrlast) {
            zrjc = lotteryService.getZrjc();
            zrbd = lotteryService.getZrBd();
            if (zrbd!=null) {
                for (int i = 0; i < zrbd.size() && i< guize.length; i++) {
                    EventUserLuckBangdanModel model = zrbd.get(i);
                    model.setYuqi((int) (zrjc*guize[i]));
                }
            }
        }

        //今日奖池
        long jrjc = 0;
        //今日榜单
        List<EventUserLuckBangdanModel> jrbd = new ArrayList<>();
        if (current<last) {
            //今日奖池
            jrjc = lotteryService.getJrjc();
            //今日榜单
            jrbd = lotteryService.getJrBd();
            if (zrbd!=null) {
                for (int i = 0; i < jrbd.size() && i< guize.length; i++) {
                    EventUserLuckBangdanModel model = jrbd.get(i);
                    model.setYuqi((int) (jrjc*guize[i]));
                }
            }
        }

        //总奖池
        long zjc = lotteryService.getZjc(startDate, endDate);
        //总榜单
        List<EventUserLuckBangdanModel> zbd = lotteryService.getZBd(startDate, endDate);
        if (zrbd!=null) {
            for (int i = 0; i < zbd.size() && i< guize.length; i++) {
                EventUserLuckBangdanModel model = zbd.get(i);
                model.setYuqi((int) (zjc*guize[i]));
            }
        }

        Map<String, Object> map = new HashMap<>();
        map.put("zrjc",zrjc);
        map.put("jrjc",jrjc);
        map.put("zjc",zjc);
        map.put("zrbd",zrbd);
        map.put("jrbd",jrbd);
        map.put("zbd",zbd);

        System.out.println("存缓存");
        // redis 缓存
        if (map!=null) {
            ValueOperations valueOperations = redisTemplate.opsForValue();
            String json = JSON.toJSONString(map);
            valueOperations.set(key_cahe_contribution, json, 15, TimeUnit.MINUTES);
        }
        return map;
    }

    //鱼卡活动
    public Map<String, Object>  yuka() {
        String startDate = "2020-09-04"; //活动开始时间
        String endDate = "2020-09-10";  //活动结束时间
        String lastDate = "2020-09-11";  //活动结束时间
        String zrlastDate = "2020-09-12";  //活动结束时间
        //检查活动时间
        long start = StrToMillsUtil.strToMillsShort(startDate);
        long end = StrToMillsUtil.strToMillsShort(endDate);
        long last = StrToMillsUtil.strToMillsShort(lastDate);
        long zrlast = StrToMillsUtil.strToMillsShort(zrlastDate);
        long current = System.currentTimeMillis()/1000;

        if (start>current) {
            Map<String, Object> map = new HashMap<>();
            map.put("yukalist",new ArrayList<>());
            map.put("zrbd",new ArrayList<>());
            map.put("jrbd",new ArrayList<>());
            map.put("zbd",new ArrayList<>());
            //活动未开始
            return map;
        }


        //昨日奖池
        List<EventUserLuckBangdanModel> zrbd = new ArrayList<>();
        //昨日榜单
        if (!startDate.equals(StrToMillsUtil.millsToStrDate(new Date(), null)) && current<zrlast) {
            zrbd = lotteryService.getZrBdYk();
        }

        //今日榜单
        List<EventUserLuckBangdanModel> jrbd = new ArrayList<>();
        if (current<last) {
            //今日榜单
            jrbd = lotteryService.getJrBdYk();
        }

        //总榜单
        List<EventUserLuckBangdanModel> zbd = lotteryService.getZBdYk(startDate, endDate);

        //鱼卡
        List<EventUserLuckBangdanModel> yukalist = lotteryService.getYukalist(startDate, endDate);

        Map<String, Object> map = new HashMap<>();
        map.put("yukalist",yukalist);
        map.put("zrbd",zrbd);
        map.put("jrbd",jrbd);
        map.put("zbd",zbd);
        return map;
    }

    public Map<String, Object> haiou() {
        //取缓存  如果没有 再取数据库
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String json = (String) valueOperations.get(key_cahe_haiou);

        Map<String, Object> cache = (Map<String, Object>) JSON.parse(json);
        if (cache==null) {
            Map<String, Object> map = new HashMap<>();
            map.put("count", 0);
            map.put("bd1",new ArrayList<>());
            map.put("bd2",new ArrayList<>());
            map.put("bd3",new ArrayList<>());
            map.put("bd4",new ArrayList<>());
            return map;
        }
        return cache;
    }

    //海鸥
    public void setHaiou() {
        String startDate = "2020-09-15"; //活动开始时间
        //检查活动时间
        long start = StrToMillsUtil.strToMillsShort(startDate);
        long current = System.currentTimeMillis()/1000;

        if (start>current) return;

        int count = lotteryService.getHaiouCount();

        //用户分成点数  1+2+3+4+6+8+11+15+20+30
        double[] guize = new double[]{0.3d, 0.2d, 0.15d, 0.11d, 0.08d, 0.06d, 0.04d, 0.03d, 0.02d, 0.01d};

        List<EventUserLuckBangdanModel> bd1 = lotteryService.getHaiouBd1();
        if (bd1==null) bd1 = new ArrayList<>();

        int jc1 = 100000;
        for (int i = 0; i < bd1.size() && i< guize.length; i++) {
            EventUserLuckBangdanModel model = bd1.get(i);
            model.setYuqi((int) (jc1*guize[i]));
        }

        List<EventUserLuckBangdanModel> bd2 = lotteryService.getHaiouBd2();
        if (bd2==null) bd2 = new ArrayList<>();
        int jc2 = 300000;
        for (int i = 0; i < bd2.size() && i< guize.length; i++) {
            EventUserLuckBangdanModel model = bd2.get(i);
            model.setYuqi((int) (jc2*guize[i]));
        }

        List<EventUserLuckBangdanModel> bd3 = lotteryService.getHaiouBd3();
        if (bd3==null) bd3 = new ArrayList<>();
        int jc3 = 600000;
        for (int i = 0; i < bd3.size() && i< guize.length; i++) {
            EventUserLuckBangdanModel model = bd3.get(i);
            model.setYuqi((int) (jc3*guize[i]));
        }

        List<EventUserLuckBangdanModel> bd4 = lotteryService.getHaiouBd4();
        if (bd4==null) bd4 = new ArrayList<>();
        int jc4 = 1000000;
        for (int i = 0; i < bd4.size() && i< guize.length; i++) {
            EventUserLuckBangdanModel model = bd4.get(i);
            model.setYuqi((int) (jc4*guize[i]));
        }

        Map<String, Object> map = new HashMap<>();
        map.put("count", count);
        map.put("bd1", bd1);
        map.put("bd2", bd2);
        map.put("bd3", bd3);
        map.put("bd4", bd4);

        // redis 缓存
        if (map!=null) {
            ValueOperations valueOperations = redisTemplate.opsForValue();
            String json = JSON.toJSONString(map);
            valueOperations.set(key_cahe_haiou, json, 15, TimeUnit.MINUTES);
        }

        System.out.println("统计海鸥："+count);
    }

    public Map<String, Object> getLianMeng() {
        //取缓存  如果没有 再取数据库
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String json = (String) valueOperations.get(key_cahe_contribution);

        Map<String, Object> cache = (Map<String, Object>) JSON.parse(json);
        if (cache==null) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            return map;
        }
        return cache;
    }

    //聊天室联盟
    public  Map<String, Object> setLianMeng() {
        System.out.println("刷新活动数据");
        String startDate = "2021-01-11"; //活动开始时间 包含
        String endDate = "2021-01-17";  //活动结束时间 包含
        //检查活动时间
        long start = StrToMillsUtil.strToMillsShort(startDate);
        long end = StrToMillsUtil.strToMillsShort(endDate);
        long current = System.currentTimeMillis()/1000;

        if (start>current) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            //活动未开始
            return map;
        }

        //房间分成点数
        double[] guize = new double[]{0.3d, 0.2d, 0.15d, 0.11d, 0.08d, 0.06d, 0.04d, 0.03d, 0.02d, 0.01d};

        //总奖池
        long zjc = lotteryService.getZjc(startDate, endDate);
        //总榜单
        List<LianMengBangdanModel> zbd = lotteryService.getLianMengBd (startDate, endDate);
        if (zbd!=null) {
            for (int i = 0; i < zbd.size(); i++) {
                LianMengBangdanModel model = zbd.get(i);
                Room room = roomService.getById(model.getRoomId());
                model.setName(room.getName());
                model.setRoomId(room.getUuid());
                User host = userService.getById(room.getUserId());
                model.setImg(host.getImg());
                if(i>0) {
                    model.setSym(zbd.get(i-1).getPay()-model.getPay());
                }

                if (i< guize.length) {
                    model.setYuqi((int) (zjc * guize[i]));
                    model.setHostYuqi((int) (model.getYuqi() * 0.2d));
                    List<UserLianMengModel> userModels = lotteryService.getLianMengBdInroom(startDate, endDate, room.getId())
                            .stream().filter(u -> u.getPay() * 10 > model.getPay()).collect(Collectors.toList());

                    //大户总贡献
                    int totalPay = userModels.stream().mapToInt(u -> u.getPay()).sum();
                    for (UserLianMengModel userModel : userModels) {
                        User user = userService.getById(userModel.getUserId());
                        userModel.setImg(user.getImg());
                        userModel.setName(user.getName());
                        userModel.setSex(user.getSex());
                        userModel.setLevel(user.getLevel());
                        userModel.setRate(BigDecimal.valueOf(userModel.getPay()*100).divide(BigDecimal.valueOf(totalPay), 2, RoundingMode.HALF_UP).doubleValue());
                        userModel.setYuqi((int) (userModel.getPay() * 1.0d / totalPay * model.getYuqi() * 0.8d));
                    }
                    model.setList(userModels);
                }
            }
        }

        Map<String, Object> map = new HashMap<>();
        map.put("zjc",zjc);
        map.put("zbd",zbd);

        System.out.println("存缓存");
        // redis 缓存
        if (map!=null) {
            ValueOperations valueOperations = redisTemplate.opsForValue();
            String json = JSON.toJSONString(map);
            valueOperations.set(key_cahe_contribution, json, 15, TimeUnit.MINUTES);
        }
        return map;
    }

    public List<WalletRecord> hd5() {
        //取缓存  如果没有 再取数据库
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String json = (String) valueOperations.get(key_cahe_hd5);
        List<WalletRecord> walletRecords = (List<WalletRecord>) JSON.parse(json);
        if (walletRecords==null) {
            walletRecords = walletRecordService.hd5();
            json = JSON.toJSONString(walletRecords);
            valueOperations.set(key_cahe_hd5, json, 1, TimeUnit.MINUTES);
        }
        return walletRecords;
    }

    /**哈哈牛活动1*/
    public Map<String, Object> getHahaniu1() {
        //取缓存  如果没有 再取数据库
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String json = (String) valueOperations.get(key_cahe_contribution);

        Map<String, Object> cache = (Map<String, Object>) JSON.parse(json);
        if (cache==null) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            return map;
        }
        return cache;
    }

    /**哈哈牛活动1*/
    public  Map<String, Object> cacheHahaniu1() {
        System.out.println("刷新活动数据");
        String startDate = "2021-02-15"; //活动开始时间 包含
        String endDate = "2021-02-21";  //活动结束时间 包含
        //检查活动时间
        long start = StrToMillsUtil.strToMillsShort(startDate);
        long end = StrToMillsUtil.strToMillsShort(endDate);
        long current = System.currentTimeMillis()/1000;

        if (start>current) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            //活动未开始
            return map;
        }

        //房间分成点数
        double[] guize = new double[]{0.3d, 0.2d, 0.15d, 0.11d, 0.08d, 0.06d, 0.04d, 0.03d, 0.02d, 0.01d};

        //总奖池
        long zjc = lotteryService.getZjc(startDate, endDate);
        //总榜单
        List<LianMengBangdanModel> zbd = lotteryService.getHahaniuHd1Bd (startDate, endDate);

        if (zbd!=null) {
            for (int i = 0; i < zbd.size(); i++) {
                LianMengBangdanModel model = zbd.get(i);
                Room room = roomService.getById(model.getRoomId());
                model.setName(room.getName());
                model.setRoomId(room.getUuid());
                User host = userService.getById(room.getUserId());
                model.setImg(host.getImg());
                if(i>0) {
                    model.setSym(zbd.get(i-1).getPay()-model.getPay());
                }

                if (i< guize.length) {
                    model.setYuqi((int) (zjc * guize[i]));
                }
            }
        }

        Map<String, Object> map = new HashMap<>();
        map.put("zjc",zjc);
        map.put("zbd",zbd);

        System.out.println("存缓存");
        // redis 缓存
        if (map!=null) {
            ValueOperations valueOperations = redisTemplate.opsForValue();
            String json = JSON.toJSONString(map);
            valueOperations.set(key_cahe_contribution, json, 15, TimeUnit.MINUTES);
        }
        return map;
    }


    /**哈哈牛活动2*/
    public Map<String, Object> getHahaniu2() {
        //取缓存  如果没有 再取数据库
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String json = (String) valueOperations.get(key_cahe_hahaniu2);

        Map<String, Object> cache = (Map<String, Object>) JSON.parse(json);
        if (cache==null) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            return map;
        }
        return cache;
    }

    /**哈哈牛活动2*/
    public  Map<String, Object> cacheHahaniu2() {
        System.out.println("刷新活动数据");
        String startDate = "2021-02-22"; //活动开始时间 包含
        String endDate = "2021-02-28";  //活动结束时间 包含
        //检查活动时间
        long start = StrToMillsUtil.strToMillsShort(startDate);
        long end = StrToMillsUtil.strToMillsShort(endDate);
        long current = System.currentTimeMillis()/1000;

        if (start>current) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            //活动未开始
            return map;
        }

        //房间分成点数
        double[] guize = new double[]{0.3d, 0.2d, 0.15d, 0.11d, 0.08d, 0.06d, 0.04d, 0.03d, 0.02d, 0.01d};

        //总奖池
        long zjc = lotteryService.getZjc2(startDate, endDate);
        //总榜单
        List<LianMengBangdanModel> zbd = lotteryService.getHahaniuHd2Bd (startDate, endDate);

        if (zbd!=null) {
            for (int i = 0; i < zbd.size(); i++) {
                LianMengBangdanModel model = zbd.get(i);
                Room room = roomService.getById(model.getRoomId());
                model.setName(room.getName());
                model.setRoomId(room.getUuid());
                User host = userService.getById(room.getUserId());
                model.setImg(host.getImg());
                if(i>0) {
                    model.setSym(zbd.get(i-1).getPay()-model.getPay());
                }

                if (i< guize.length) {
                    model.setYuqi((int) (zjc * guize[i]));
                }
            }
        }

        Map<String, Object> map = new HashMap<>();
        map.put("zjc",zjc);
        map.put("zbd",zbd);

        System.out.println("存缓存");
        // redis 缓存
        if (map!=null) {
            ValueOperations valueOperations = redisTemplate.opsForValue();
            String json = JSON.toJSONString(map);
            valueOperations.set(key_cahe_hahaniu2, json, 15, TimeUnit.MINUTES);
        }
        return map;
    }

    /**哈哈牛活动2*/
    public Map<String, Object> getNaonao1() {
        //取缓存  如果没有 再取数据库
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String json = (String) valueOperations.get(key_cahe_naonao1);

        Map<String, Object> cache = (Map<String, Object>) JSON.parse(json);
        if (cache==null) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            return map;
        }
        return cache;
    }

    /**哈哈牛活动2*/
    public  Map<String, Object> cacheNaonao1() {
        System.out.println("刷新活动数据");
        String startDate = "2021-03-01"; //活动开始时间 包含
        String endDate = "2021-03-07";  //活动结束时间 包含
        //检查活动时间
        long start = StrToMillsUtil.strToMillsShort(startDate);
        long end = StrToMillsUtil.strToMillsShort(endDate);
        long current = System.currentTimeMillis()/1000;

        if (start>current) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            //活动未开始
            return map;
        }

        //房间分成点数
        double[] guize = new double[]{0.35d, 0.25d, 0.2d, 0.1d, 0.1d};

        //总奖池
        long zjc = lotteryService.getZjc2(startDate, endDate);
        zjc+=100000;
        //总榜单
        List<LianMengBangdanModel> zbd = lotteryService.getNaonaoHd1Bd(startDate, endDate);

        if (zbd!=null) {
            for (int i = 0; i < zbd.size(); i++) {
                LianMengBangdanModel model = zbd.get(i);
                Room room = roomService.getById(model.getRoomId());
                model.setName(room.getName());
                model.setRoomId(room.getUuid());
                User host = userService.getById(room.getUserId());
                model.setImg(host.getImg());
                if(i>0) {
                    model.setSym(zbd.get(i-1).getPay()-model.getPay());
                }

                if (i< guize.length) {
                    model.setYuqi((int) (zjc * guize[i]));
                } else if (i<10) {
                    model.setYuqi(8888);
                }
            }
        }

        Map<String, Object> map = new HashMap<>();
        map.put("zjc",zjc);
        map.put("zbd",zbd);

        System.out.println("存缓存");
        // redis 缓存
        if (map!=null) {
            ValueOperations valueOperations = redisTemplate.opsForValue();
            String json = JSON.toJSONString(map);
            valueOperations.set(key_cahe_naonao1, json, 15, TimeUnit.MINUTES);
        }
        return map;
    }


    /**咚咚熊活动1*/
    public Map<String, Object> getDongdongxiong1() {
        //取缓存  如果没有 再取数据库
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String json = (String) valueOperations.get(key_cahe_naonao1);

        Map<String, Object> cache = (Map<String, Object>) JSON.parse(json);
        if (cache==null) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            return map;
        }
        return cache;
    }

    /**咚咚熊活动1*/
    public  Map<String, Object> cacheDongdongxiong1() {
        System.out.println("刷新活动数据03-25");
        String startDate = "2021-03-22"; //活动开始时间 包含
        String endDate = "2021-03-25";  //活动结束时间 包含
        //检查活动时间
        long start = StrToMillsUtil.strToMillsShort(startDate);
        long end = StrToMillsUtil.strToMillsShort(endDate);
        long current = System.currentTimeMillis()/1000;

        if (start>current) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            //活动未开始
            return map;
        }

        //房间分成点数
        double[] guize = new double[]{0.35d, 0.25d, 0.2d, 0.1d, 0.1d};

        //总奖池
        long zjc = lotteryService.getZjc2(startDate, endDate);
        //总榜单
        List<EventUserLuckBangdanModel> zbd = lotteryService.getZBdPay(startDate, endDate);
        for (int i = 0; i < zbd.size() && i< 10; i++) {
            if (i<guize.length) {
                EventUserLuckBangdanModel model = zbd.get(i);
                model.setYuqi((int) (zjc * guize[i]));
            } else {
                zbd.get(i).setYuqi(13140);
            }
        }


        Map<String, Object> map = new HashMap<>();
        map.put("zjc",zjc);
        map.put("zbd",zbd);

        System.out.println("存缓存");
        // redis 缓存
        if (map!=null) {
            ValueOperations valueOperations = redisTemplate.opsForValue();
            String json = JSON.toJSONString(map);
            valueOperations.set(key_cahe_naonao1, json, 15, TimeUnit.MINUTES);
        }
        return map;
    }

    /**咚咚熊活动1*/
    public Map<String, Object> getDongdongxiong2() {
        //取缓存  如果没有 再取数据库
        ValueOperations valueOperations = redisTemplate.opsForValue();
        String json = (String) valueOperations.get(key_cahe_naonao2);

        Map<String, Object> cache = (Map<String, Object>) JSON.parse(json);
        if (cache==null) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            return map;
        }
        return cache;
    }

    /**咚咚熊活动1*/
    public  Map<String, Object> cacheDongdongxiong2() {
        System.out.println("刷新活动数据2021-04-04");
        String startDate = "2021-03-26"; //活动开始时间 包含
        String endDate = "2021-04-04";  //活动结束时间 包含
        //检查活动时间
        long start = StrToMillsUtil.strToMillsShort(startDate);
        long end = StrToMillsUtil.strToMillsShort(endDate);
        long current = System.currentTimeMillis()/1000;

        if (start>current) {
            Map<String, Object> map = new HashMap<>();
            map.put("zjc", 0);
            map.put("zbd",new ArrayList<>());
            //活动未开始
            return map;
        }

        //房间分成点数
        double[] guize = new double[]{0.35d, 0.25d, 0.2d, 0.1d, 0.1d};

        //总奖池
        long zjc = lotteryService.getZjc2(startDate, endDate);
        //总榜单
        List<EventUserLuckBangdanModel> zbd = lotteryService.getRoomZBdPay(startDate, endDate);
        for (int i = 0; i < zbd.size() && i< 10; i++) {
            if (i<guize.length) {
                EventUserLuckBangdanModel model = zbd.get(i);
                model.setYuqi((int) (zjc * guize[i]));
            } else {
                zbd.get(i).setYuqi(13140);
            }
        }


        Map<String, Object> map = new HashMap<>();
        map.put("zjc",zjc);
        map.put("zbd",zbd);

        System.out.println("存缓存");
        // redis 缓存
        if (map!=null) {
            ValueOperations valueOperations = redisTemplate.opsForValue();
            String json = JSON.toJSONString(map);
            valueOperations.set(key_cahe_naonao2, json, 15, TimeUnit.MINUTES);
        }
        return map;
    }
}